<extend name="Public/base" />
<block name="content">
    <center>
        <table style="margin-top: 5%">
            <theat>
                <th>考试名称</th>
                <th style="text-align: center">考试占比</th>
            </theat>
            <tbody>
            <volist name="res" id="res">
                <tr>
                    <td><{$res.val}></td>
                    <td>
                        <input type="text" class="as" value="<{$res.percent}>" disabled style="height:25px;border-radius: 5px" onblur="addP()">
                        <input type="hidden" class="ds" value="<{$res.dict_id}>">
                    </td>
                </tr>
            </volist>
            <tr>
                <td>总和</td>
                <td id="zh"><{$nu}></td>
            </tr>
            </tbody>
            <tfoot>
                <td colspan="2" style="padding-left:37% ">
                    <buttom class="button tiny  radius xg" onclick="xg()">修改</buttom>
                    <buttom class="button tiny  radius bc" style="display:none" onclick="bc()">保存</buttom>
                </td>
            </tfoot>
        </table>
    </center>
    <script>
        function xg() {
            $('.xg').hide();
            $('.bc').show();
            $('.as').prop('disabled',false);
        }
        function bc() {
            if ($('#zh').html()=='100'){
                $('.bc').hide();
                $('.xg').show();
                $('.as').prop('disabled', true);
                var did = $('.ds').map(function () {return $(this).val();}).get().join(',');
                var per = $('.as').map(function () {return $(this).val();}).get().join(',');
                var data={
                    id:did,
                    per:per,
                };
                $.post("<{:U('Percent/add')}>",data,function (data) {
                    alert(data);
                })
            }else{
                alert('总和不为100,请修改');
            }
        }
        function addP() {
            var a=$('.as').map(function (){return $(this).val();}).get();
            var b=0;
            for(i in a){
                b=b+parseInt(a[i]);
            }
            $('#zh').html(b);
        }
    </script>
</block>